#!/bin/sh
readINI()
{
 FILENAME=$1; SECTION=$2; KEY=$3
 RESULT=`awk -F '=' '/\['$SECTION'\]/{a=1}a==1&&$1~/'$KEY'/{print $2;exit}' $FILENAME`
 echo $RESULT
}

evnmode="development"
# debug log
# echo $evnmode

# set config path.
cfg_path="../config/cfg-"$evnmode".ini"
# debug log.
# echo $cfg_path

# create folders, chanage permission.
mkdir ../logs ../config
cp -rf inspection.json ../config
cp -rf regist_conf ../config
cp -rf cfg-example.ini $cfg_path
chmod 777 -R ../config

# init configure.
sed -i 's!{rpc_service}!'$(readINI docker_init.ini $evnmode RPC_SERVICE)'!g' $cfg_path \
&& sed -i 's/{mongodb_host}/'$(readINI docker_init.ini $evnmode MONGO_DB_HOST)'/g' $cfg_path \
&& sed -i 's/{mysql_host}/'$(readINI docker_init.ini $evnmode MYSQL_DB_HOST)'/g' $cfg_path \
&& sed -i 's/{service_host}/'$(readINI docker_init.ini $evnmode SERVICE_HOST)'/g' $cfg_path \
&& sed -i 's/{service_port}/'$(readINI docker_init.ini $evnmode SERVICE_PORT)'/g' $cfg_path \
&& sed -i 's/{service_db_name}/'$(readINI docker_init.ini $evnmode DB_NAME)'/g' $cfg_path \
&& sed -i 's/{debug}/'$(readINI docker_init.ini $evnmode DEBUG)'/g' $cfg_path
# debug log.